#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "ssm.h"


void printControl(Control source)
{
	printf("placeholder     = %d\n", source.placeholder);
}

int writeControl(char* filename, Control *source)
{
	FILE *fp;
	if((fp=fopen(filename, "wb")) == NULL) 
	{//error opening file
  		fprintf(stderr,"ERROR: can not open %s for output\n", filename);
  		exit(1);
	}
	if((fwrite(source, sizeof(Control), 1, fp)) == -1)
	{//write failed
		fprintf(stderr,"ERROR: could not write record\n");
	}
	fclose(fp);
	return 0;
}

int readControl(char* filename, Control *dest)
{
	FILE *fp;
	if((fp=fopen(filename,"rb")) == NULL) 
	{//error opening file
  		fprintf(stderr,"ERROR: can not open %s for input\n", filename);
  		exit(1);
	}
	if((fread(dest, sizeof(Control), 1, fp)) == -1)
	{//write failed
		fprintf(stderr,"ERROR: could not write record\n");
	}
	fclose(fp);
	return 0;
}
